package com.szzg10.thinking.chapter11;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class ListIteration {

	public static void main(String[] args) {
		List<Pet> pets = new ArrayList<Pet>();
		pets.add(new Rat());
		pets.add(new Manx());
		pets.add(new Cymric());
		pets.add(new Mutt());
		pets.add(new Pug());
		pets.add(new Cymric());
		pets.add(new Pug());
		
		ListIterator<Pet> listIterator = pets.listIterator();
		while(listIterator.hasNext()) {
			System.out.println(listIterator.next() + ", " + listIterator.nextIndex() + ", " + listIterator.previousIndex());
		}
		System.out.println();
		
		while(listIterator.hasPrevious()) {
			System.out.println(listIterator.previous());
		}
		System.out.println();
		
		System.out.println(pets);
		
		listIterator = pets.listIterator(3);
		while(listIterator.hasNext()) {
			listIterator.next();
			listIterator.set(new Rat());
		}
		System.out.println(pets);
	}
}
